You write custom CUDA kernels to replace PyTorch operators for speedups.
Implement a Dual-Input Contrastive Gate: Given two tensors a and b of shape [B, D], compute y = tanh(a - b) * sigmoid(alpha * (a + b) + beta). The CUDA kernel must fuse both inputs in a single pass with grid-stride loops over total elements, using contiguous memory and minimizing intermediate reads/writes. Provide a PyTorch reference module using nn.Parameters for alpha and beta, and ensure outputs match within rtol=1e-3. This operator emphasizes pairwise contrast and gated aggregation in one kernel.
